package edu.cqie.smartfarm.controller;


import cn.hutool.core.bean.BeanUtil;
import edu.cqie.smartfarm.constant.CommonConstant;
import edu.cqie.smartfarm.entity.DictionaryList;
import edu.cqie.smartfarm.result.R;
import edu.cqie.smartfarm.service.IDictionaryListService;
import edu.cqie.smartfarm.vo.DictionaryListVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author yyw
 * @since 2024-12-26
 */
@RestController
@RequestMapping("/dictionary-list")
@RequiredArgsConstructor
@Api(tags = "字典列表")
public class DictionaryListController {

    private final IDictionaryListService dictionaryListService;

    @ApiOperation(value = "获取字典列表")
    @GetMapping("/list")
    @Cacheable(value = CommonConstant.PROJECT_NAME+":dictionaryList", key = "'dictionaryList'")
    //@Cacheable(value = "dictionaryList")
    public R<List<DictionaryListVO>> getList(){
        List<DictionaryList> list = dictionaryListService.list();
        return R.Success(BeanUtil.copyToList(list, DictionaryListVO.class));
    }
}
